<template>
  <view class="skeleton-container" v-if="show">
    <!-- 商品推荐骨架屏 -->
    <view class="skeleton-section">
      <view class="skeleton-section-header">
        <view class="skeleton-title"></view>
        <view class="skeleton-more"></view>
      </view>
      <view class="skeleton-recommend-grid">
        <view class="skeleton-recommend-item" v-for="i in 4" :key="i">
          <view class="skeleton-product-image"></view>
          <view class="skeleton-product-info">
            <view class="skeleton-product-name"></view>
            <view class="skeleton-product-price"></view>
          </view>
        </view>
      </view>
    </view>

    <!-- AI推荐骨架屏 -->
    <view class="skeleton-section">
      <view class="skeleton-section-header">
        <view class="skeleton-title"></view>
        <view class="skeleton-more"></view>
      </view>
      <view class="skeleton-ai-recommend">
        <view class="skeleton-ai-card">
          <view class="skeleton-ai-header">
            <view class="skeleton-ai-icon"></view>
            <view class="skeleton-ai-title"></view>
          </view>
          <view class="skeleton-ai-body">
            <view class="skeleton-ai-description"></view>
            <view class="skeleton-ai-button"></view>
          </view>
        </view>
      </view>
    </view>

    <!-- 广告骨架屏 -->
    <view class="skeleton-section">
      <view class="skeleton-section-header">
        <view class="skeleton-title"></view>
      </view>
      <scroll-view scroll-x class="skeleton-ad-scroll">
        <view class="skeleton-ad-item" v-for="i in 5" :key="i">
          <view class="skeleton-ad-image"></view>
        </view>
      </scroll-view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { defineProps } from 'vue';

defineProps({
  show: {
    type: Boolean,
    default: false
  }
});
</script>

<style>
.skeleton-container {
  padding: 10px;
  background-color: #f8f8f8;
}

/* 通用区块样式 */
.skeleton-section {
  margin-bottom: 20px;
  background-color: #fff;
  border-radius: 12px;
  padding: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.skeleton-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.skeleton-title {
  width: 80px;
  height: 20px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

.skeleton-more {
  width: 40px;
  height: 16px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

/* 商品推荐骨架屏 */
.skeleton-recommend-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.skeleton-recommend-item {
  background-color: #f8f8f8;
  border-radius: 8px;
  overflow: hidden;
}

.skeleton-product-image {
  width: 100%;
  height: 120px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.skeleton-product-info {
  padding: 10px;
}

.skeleton-product-name {
  width: 100%;
  height: 16px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
  margin-bottom: 8px;
}

.skeleton-product-price {
  width: 70%;
  height: 14px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

/* AI推荐骨架屏 */
.skeleton-ai-recommend {
  padding: 20px;
  background-color: #f8f8f8;
  border-radius: 12px;
}

.skeleton-ai-card {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.skeleton-ai-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.skeleton-ai-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.skeleton-ai-title {
  width: 100px;
  height: 18px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

.skeleton-ai-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skeleton-ai-description {
  width: 100%;
  height: 14px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

.skeleton-ai-button {
  width: 120px;
  height: 36px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 18px;
  align-self: center;
}

/* 广告骨架屏 */
.skeleton-ad-scroll {
  white-space: nowrap;
}

.skeleton-ad-item {
  display: inline-block;
  width: 120px;
  height: 80px;
  margin-right: 10px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

/* 闪烁动画 */
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}
</style> 